﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PasswordManager
{
    public partial class ChangePassword : Form
    {
        private Point p;
        public string NewPassword { get; set; }
        private string password;
        public ChangePassword(string password,Point p)
        {
            this.p = p;
            this.password = password;
            this.NewPassword = "";
            InitializeComponent();
            textBox_newPassword.Text = "";
            textBox_currentPassword.Text = "";
            textBox_confirmPassword.Text = "";
            textBox_currentPassword.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox_currentPassword.Text!=this.password)
            {
                MessageBox.Show("You have to enter valid current password!","Error");
                this.Close();
                return;
            }
            if (textBox_confirmPassword.Text == textBox_newPassword.Text)
            {
                this.NewPassword = textBox_newPassword.Text;
                this.Close();
                return;
            }
            else
            {
                MessageBox.Show("Password and Password confirmation does not match", "Error");
            }
        }

        private void textBox_confirmPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(new object(), new EventArgs());
            }
        }

        private void ChangePassword_Load(object sender, EventArgs e)
        {
            this.Location = this.p;
        }

    }
}
